package Model;

import Entity.LoanType;
import Manager.LoanTypeManager;
import Manager.Manager;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author CONG
 */
public class LoanTypeTableModel extends AbstractTableModel {

    private Manager manager;
    public LoanTypeTableModel(Manager manager) {
        this.manager = manager;
    }

    @Override
    public int getRowCount() {
        return  manager.getLoanTypeManager().getSize();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        LoanType lt = manager.getLoanTypeManager().getLoanType(rowIndex);
        switch (columnIndex) {
            case 0:
                return lt.getLoanTypeCode();
            case 1:
                return lt.getName();
            case 2:
                return lt.getDescription();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Name";
            case 2:
                return "Description";
            default:
                return null;
        }
    }

    public int getSize() {
        return manager.getLoanTypeManager().getSize();
    }

    public LoanType getLoanType(int index) {
        return manager.getLoanTypeManager().getLoanType(index);
    }

    public void getLoanTypeList(ArrayList<LoanType> lt) {
        manager.getLoanTypeManager().getLoanTypeList(lt);
    }
    public boolean addLoanType(LoanType lt){
        return manager.getLoanTypeManager().addLoanType(lt);
    }
    public boolean updateLoanType(LoanType lt){
        return manager.getLoanTypeManager().updateLoanType(lt);
    }
    public boolean deleteLoanType(LoanType lt){
        return manager.getLoanTypeManager().deleteLoanType(lt);
    }
}
